Overview
SharePoint Framework extensions extend the user experience toward the Modern Framework List and Library to render custom components.
When we deploy an SPFx extension List View Command set at the site collection level, by default, it’s available to all lists and libraries.
In this article, we are going to learn how to restrict the List View command set to a specific List or Library.
Let’s get started.
Step 1
Add List view command set using SharePoint Framework Extension
- Type Code .
It will open the project into an open source IDE, i.e., Visual Studio Code (condition - Visual Studio Code needs to installed on your system).
Step 1 - Navigate to the Typecript file
Src -> extrensions -> metatdata -> MetadataCommandSet.ts
- compareOneCommand.visible = event.selectedRows.length === 1;
- public onListViewUpdated(event: IListViewCommandSetListViewUpdatedParameters): void {
- var Libraryurl = this.context.pageContext.list.title;
- const compareOneCommand: Command = this.tryGetCommand('COMMAND_1');
- if (compareOneCommand) {
- // This command should be hidden unless exactly one row is selected.
- compareOneCommand.visible = (event.selectedRows.length === 1 && Libraryurl == "BotFiles" );
- }
- }
In the above code snippet, I have set the Library Url with current page list title, checked the condition if it's equal to the defined list or library, then made command set visible.
Step 3 - Build, Bundle and Package the Solution
Navigate to View -> Integrated Terminal

- Run Gulp Build
- Run Gulp Bundle –ship
- Run Gulp Package-solution –ship
I prefer to deploy at the site collection for this demo.
Navigate to Modern site collection.
Go to Site Content -> App for SharePoint -> Upload the .SPPKG file and click to deploy the solution.
If the same package already exists, don’t forget to check in the package otherwise it will not be available to other audiences.
Navigate to Library; i.e. Targeted template.


Bhushan MittalPosted May 2, 2023, 1:06 PM
Nice but looks like it won't work in case of multilingual sites
vamsidhar madunuriPosted Jan 22, 2021, 10:26 AM
Can we restrict spfx listview command set button to a specific view(only AllDocuments view show the custom button)
Jon KlevelandPosted Apr 2, 2020, 2:25 AM
Hi. What if you use a List WebPart to show the "BotFiles" list on another page (t.ex home page), then it seems like this.context.pageContext.list.title = SitePages ...?